<%@ page language="java" import="java.util.*,java.sql.*,org.json.*,com.ruohi.util.dbutil.*,com.ruohi.util.common.*,com.ruohi.manage.*" pageEncoding="UTF-8"%>
<%@page import="com.ruohi.gift.order.OrderOperate"%>
<%@page import="com.ruohi.gift.order.OrderStatus"%>
<%

	Connection conn = null;
	DBHelper dbHelper = DBHelper.getInstance();
	try{
		conn = PoolManager.getConnection(DBType.getDBTypeByEnum("106010"));
		
		int days = 1;//默认不设置为1天
		String enum_sql = " select top 1 val from service_common_enum where parent_no='203001' ";
		Map enum_enumMap = dbHelper.getMap(enum_sql, conn);
		if(enum_enumMap!=null){
			days = CommonString.getFormatInt(enum_enumMap.get("val"));
		}
		
		String whereStr = " and order_status = 1 and DATEDIFF(day,add_date,GETDATE())>"+days ;//1为等待付款订单
		if(days>=1){
			
			String dataSql = " select order_num from gift_order where "+whereStr;
			List<Map> dataList = dbHelper.getMapList(dataSql,conn);
			
			if(dataList!=null){
				//更新
				String updateSql = "update gift_order set order_status=0 where 1=1 and "+whereStr;
				//dbHelper.execute(updateSql,conn);
				
				//写入操作记录表
				for(Map m : dataList){
					String order_num = CommonString.getFormatPara(m.get("order_num"));
					
					String historySql = "insert into gift_order_operate_history (add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip) values (?,?,?,?,?,?,?,?,?,?)";
					String add_user = CommonString.getFormatPara("program");
					String add_date = CommonDate.getToday("yyyy-MM-dd HH:mm:ss");
					String add_ip = Common.getIp(request);
					String uuid = UUID.randomUUID().toString();
					String mem_no = CommonString.getFormatPara("program");
					int order_status = OrderStatus.CANCELED;
					String last_modify_user = add_user;
					String last_modify_date = add_date;
					String last_modify_ip = add_ip;
					Object[] paras = { add_user,add_date,add_ip,uuid,order_num,mem_no,order_status,last_modify_user,last_modify_date,last_modify_ip };
					//dbHelper.execute(historySql,paras,conn);
				}
			}
			
		}
		
		
		
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		DBHelper.freeConnection(conn);
	}
%>